#include "StdAfx.h"
#include "SystemFacade.h"


SystemFacade::SystemFacade()	
{
	network = new Network();
	network->loadFromFile("config.txt");
}


SystemFacade::~SystemFacade(void)
{
}

int SystemFacade::getNestsCount()	
{
	return network->getNests().size();
}

int SystemFacade::getMachinesCount(int nestId)
{
	return network->getNests()[nestId]->getMachines().size();
}

int SystemFacade::isMachineFree(int nestId, int machineId)
{
	return network->getNests()[nestId]->getMachines()[machineId]->isEmpty();
}

std::vector<int> SystemFacade::getNestOutConnections(int nestId)
{
	std::vector<std::vector<int>> transitions = network->getTransitions();
	std::vector<int> connections;
	int index = 0;

	for(std::vector<int>::iterator i = transitions[nestId].begin(); i != transitions[nestId].end(); i++)
	{
		if(*i != 0)
		{
			connections.push_back(index);
		}

		index++;
	}
						
	return connections;
}

bool SystemFacade::hasNestInConnections(int nestId)
{
	vector<vector<int>> transitions = network->getTransitions();
	int index = 0;

	for(vector<vector<int>>::iterator i = transitions.begin(); i != transitions.end(); i++)
	{
		if((*i)[nestId] != 0)
		{
			return true;
		}
	}

	return false;
}

int SystemFacade::getBufferCapacity(int nestId)
{
	return network->getNests()[nestId]->getBuffer()->getCapacity();
}

int SystemFacade::getBufferCount(int nestId)
{
	return network->getNests()[nestId]->getBuffer()->getCount();
}

void SystemFacade::tick()
{
	network->tick();
}

void SystemFacade::loadNetwork(std::string config)
{
	
}

std::string SystemFacade::readLog()
{
	string str;
	getline(network->com.log, str);

	return str;
}
